﻿/*
* ProductionArgs.js
* zhouh@ZD_20160417
*/
$(function () {
    //announcement
    var proid = $('[id$="hdfProid"]').val();
    var loadPercent = 0;
    var savePercent = 0;
    //function
    function loadMaterial(callback) { //加载全部材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divMID_B').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var code_d = o[i]['code_d']; //锻件
                    var code_z = o[i]['code_z']; //铸件
                    var mid = o[i]['MID']; //材质编号
                    var desc = code_z == code_d ? code_d : code_d + '/' + code_z;
                    var _item = item.replace('材料ID', mid).replace('材料名称', desc);
                    content.html(content.html() + _item);
                }
                $('#divMID_S').children('.itemContent').html($('#divMID_B').children('.itemContent').html()); //全部材质
                $('#divMID_I').children('.itemContent').html($('#divMID_B').children('.itemContent').html());
                $('#divMID_2').children('.itemContent').html($('#divMID_B').children('.itemContent').html());
                $('#divMID_9').children('.itemContent').html($('#divMID_B').children('.itemContent').html());
                $('#divMID_S').children('.itemContent').children('.ckbItem').children(':input').removeClass('ckbMID_B_Sub').addClass('ckbMID_S_Sub');
                $('#divMID_I').children('.itemContent').children('.ckbItem').children(':input').removeClass('ckbMID_B_Sub').addClass('ckbMID_I_Sub');
                $('#divMID_2').children('.itemContent').children('.ckbItem').children(':input').removeClass('ckbMID_B_Sub').addClass('ckbMID_2_Sub');
                $('#divMID_9').children('.itemContent').children('.ckbItem').children(':input').removeClass('ckbMID_B_Sub').addClass('ckbMID_9_Sub');
                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setMID_B() { //阀体材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialUsed',
            pid: proid,
            type: '4',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var mid = o[i]['MID'];
                    $('#divMID_B').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var materialID = $(elt).children(':input').attr('args');
                        if (mid == materialID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                    })
                }
            }
        })
    }
    function SaveMID_B() {//保存阀体材质
        var list = "";
        $('#divMID_B').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var materialID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (materialID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setMaterial',
                list: list,
                pid: proid,
                type: '4'
            }, function (data) {
                if (data == "OK") {
                    savePercent += 5;
                }
            })
        }
        else {
            savePercent += 5;
        }
    }
    function setMID_S() {//阀杆材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialUsed',
            pid: proid,
            type: '2',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var mid = o[i]['MID'];
                    $('#divMID_S').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var materialID = $(elt).children(':input').attr('args');
                        if (mid == materialID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                    })
                }
            }
        })
    }
    function SaveMID_S() { //阀杆材质
        var list = "";
        $('#divMID_S').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var materialID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (materialID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setMaterial',
                list: list,
                pid: proid,
                type: '2'
            }, function (data) {
                if (data == "OK") {
                    savePercent += 5;
                }
            })
        }
        else {
            savePercent += 5;
        }
    }
    function setMID_I() { //阀瓣材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialUsed',
            pid: proid,
            type: '3',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var mid = o[i]['MID'];
                    $('#divMID_I').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var materialID = $(elt).children(':input').attr('args');
                        if (mid == materialID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                    })
                }
            }
        })
    }
    function SaveMID_I() {//内件材质
        var list = "";
        $('#divMID_I').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var materialID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (materialID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setMaterial',
                list: list,
                pid: proid,
                type: '3'
            }, function (data) {
                if (data == "OK") {
                    savePercent += 5;
                }
            })
        }
        else {
            savePercent += 5;
        }
    }
    function setMID_2() { //阀座材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialUsed',
            pid: proid,
            type: '1',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var mid = o[i]['MID'];
                    $('#divMID_2').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var materialID = $(elt).children(':input').attr('args');
                        if (mid == materialID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                    })
                }
            }
        })
    }
    function SaveMID_2() {
        var list = "";
        $('#divMID_2').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var materialID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (materialID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setMaterial',
                list: list,
                pid: proid,
                type: '1'
            }, function (data) {
                if (data == "OK") {
                    savePercent += 5;
                }
            })
        }
        else {
            savePercent += 5;
        }
    }
    function setMID_9() { //填料材质
        $.get('ProductionArgs.aspx', {
            handler: 'getMaterialUsed',
            pid: proid,
            type: '5',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var mid = o[i]['MID'];
                    $('#divMID_9').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var materialID = $(elt).children(':input').attr('args');
                        if (mid == materialID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                    })
                }
            }
        })
    }
    function SaveMID_9() {
        var list = "";
        $('#divMID_9').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var materialID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (materialID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setMaterial',
                list: list,
                pid: proid,
                type: '5'
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadSize(callback) {//加载全部尺寸
        $.get('ProductionArgs.aspx', {
            handler: 'getSizeList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divSize').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var code_c = o[i]["Size_Code_C"]; //公制
                    var code_z = o[i]["Size_Code_S"]; //英制
                    var sid = o[i]["SID"];
                    var desc = "(公)" + code_c + " (英)" + code_z;
                    var _item = item.replace('尺寸ID', sid).replace('尺寸名称', desc);
                    content.html(content.html() + _item);
                }

                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setSize() {//设置尺寸
        $.get('ProductionArgs.aspx', {
            handler: 'getSizeUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var sid = o[i]['SID'];
                    $('#divSize').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var SizeID = $(elt).children(':input').attr('args');
                        if (SizeID == sid) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveSize() {//保存尺寸
        var list = "";
        $('#divSize').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var SizeID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (SizeID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setSize',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadPressure(callback) {//加载全部压力等级
        $.get('ProductionArgs.aspx', {
            handler: 'getPressureList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divPressure').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var code_c = o[i]["Pressure_Code_C"];
                    var code_s = o[i]["Pressure_Code_S"];
                    var PressureID = o[i]["PressureID"];
                    var desc = "(公)" + code_c + " (英)" + code_s;
                    var _item = item.replace("压力等级名称", desc).replace("压力ID", PressureID);
                    content.html(content.html() + _item);
                }

                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setPressure() {//获取压力等级
        $.get('ProductionArgs.aspx', {
            handler: 'getPressureUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var pressID = o[i]["PressureID"];
                    $('#divPressure').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var PressureID = $(elt).children(':input').attr('args');
                        if (PressureID == pressID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })

    }
    function SavePressure() {//保存压力等级
        var list = "";
        $('#divPressure').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var PressureID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (PressureID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setPressure',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadDesign(callback) {//加载全部压力等级
        $.get('ProductionArgs.aspx', {
            handler: 'getDesignList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divDesign').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var DesignID = o[i]["DesignLevelID"];
                    var desc = o[i]["Desc"];
                    var _item = item.replace("设计标准名称", desc).replace("设计ID", DesignID);
                    content.html(content.html() + _item);
                }

                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setDesign() {
        $.get('ProductionArgs.aspx', {
            handler: 'getDesignUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var DID = o[i]["DesignLevelID"];
                    $('#divDesign').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var DesignID = $(elt).children(':input').attr('args');
                        if (DID == DesignID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveDesign() {
        var list = "";
        $('#divDesign').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var DesignID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (DesignID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setDesign',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadConn(callback) {
        $.get('ProductionArgs.aspx', {
            handler: 'getConnList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divConn').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var DescZH = o[i]["DescZh"];
                    var DescEN = o[i]["DescEN"];
                    var Connid = o[i]["ConnID"];
                    var desc = DescEN + "(" + DescZH + ")";
                    var _item = item.replace("连接方式名称", desc).replace("连接ID", Connid);
                    content.html(content.html() + _item);
                }
                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setConn() {
        $.get('ProductionArgs.aspx', {
            handler: 'getConnUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var Cid = o[i]["ConnID"];
                    $('#divConn').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var ConnID = $(elt).children(':input').attr('args');
                        if (Cid == ConnID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveConn() {
        var list = "";
        $('#divConn').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var ConnID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (ConnID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setConn',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadFran(callback) {
        $.get('ProductionArgs.aspx', {
            handler: 'getFranList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divFran').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var desc = o[i]["Desc"];
                    var fid = o[i]["FranLevelID"];
                    var _item = item.replace("法兰标准名称", desc).replace("法兰标准ID", fid);
                    content.html(content.html() + _item);
                }
                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setFran() {
        $.get('ProductionArgs.aspx', {
            handler: 'getFranUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var fid = o[i]["FranLevelID"];
                    $('#divFran').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var FranID = $(elt).children(':input').attr('args');
                        if (fid == FranID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveFran() {
        var list = "";
        $('#divFran').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var FranID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (FranID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setFran',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadStruct(callback) {
        $.get('ProductionArgs.aspx', {
            handler: 'getStructList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divStruct').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var desc = o[i]["Desc"];
                    var sid = o[i]["StructLevelID"];
                    var _item = item.replace("结构标准名称", desc).replace("结构标准ID", sid);
                    content.html(content.html() + _item);
                }
                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setStruct() {
        $.get('ProductionArgs.aspx', {
            handler: 'getStructUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var sid = o[i]["StructLevelID"];
                    $('#divStruct').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var StructID = $(elt).children(':input').attr('args');
                        if (sid == StructID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveStruct() {
        var list = "";
        $('#divStruct').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var StructID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (StructID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setStruct',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function loadSeal(callback) {
        $.get('ProductionArgs.aspx', {
            handler: 'getSealList',
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                var content = $('#divSeal').children('.itemContent').eq(0);
                var item = content.html();
                content.empty();
                for (var i = 0; i < o.length; i++) {
                    var SID = o[i]["SealLevelID"];
                    var LevelType = o[i]["LevelType"];
                    var Level = o[i]["Level"];
                    var desc = LevelType + " " + Level;
                    var _item = item.replace("密封标准名称", desc).replace("密封标准ID", SID);
                    content.html(content.html() + _item);
                }
                loadPercent += 12.5;
                if (callback) {
                    callback();
                }
            }
        })
    }
    function setSeal() {
        $.get('ProductionArgs.aspx', {
            handler: 'getSealUsed',
            pid: proid,
            r: Math.random()
        }, function (data) {
            var o = JSON.parse(data);
            if (o != null && o.length > 0) {
                for (var i = 0; i < o.length; i++) {
                    var sid = o[i]["SealLevelID"];
                    $('#divSeal').children('.itemContent').children('.ckbItem').each(function (index, elt) {
                        var SealID = $(elt).children(':input').attr('args');
                        if (sid == SealID) {
                            $(elt).children(':input').prop('checked', 'true').change();
                        }
                        else {

                        }
                    })
                }
            }
        })
    }
    function SaveSeal() {
        var list = "";
        $('#divSeal').children('.itemContent').children('.ckbItem').each(function (index, elt) {
            var SealID = $(elt).children(':input').attr('args');
            if ($(elt).children(':input').prop('checked')) {
                list += (SealID + "|");
            }
        })
        if (list != "") {
            list = list.substr(0, list.length - 1);
            $.post('ProductionArgs.aspx', {
                handler: 'setSeal',
                list: list,
                pid: proid
            }, function (data) {
                if (data == "OK") {
                    savePercent += 10;
                }
            })
        }
        else {
            savePercent += 10;
        }
    }
    function checkControl(top, className) { //checkbox控制
        $(top).change(function () {
            $('.' + className).each(function (index, elt) {
                $(elt).prop('checked', $(top).prop('checked'));
            })
        })
    }
    function lblCkb() { //关联文本
        $('.lblCkb').each(function (index, elt) {
            $(elt).click(function () {
                var status = $(elt).prev(':input').prop('checked');
                if (status || status == 'checked') {
                    $(elt).prev(':input').prop('checked', '').change();
                }
                else {
                    $(elt).prev(':input').prop('checked', 'checked').change();
                }
            })
        })
    }
    function getCounts() { //获取已选数量，处理变更
        cal();
        $('[type="checkbox"]').change(function () {
            cal();
        })
        function cal() {
            $('.itemContent').each(function (index, elt) {
                var label = $(elt).parent('div').prev().find('.num');
                var count = 0;
                $(elt).children('.ckbItem').each(function (index2, elt2) {
                    if ($(elt2).find(':input').prop('checked')) {
                        count += 1;
                    }
                })
                label.html(count);
            })
        }
    }
    function loadAll() {
        $("#dialog").dialog("open");
        loadMaterial(function () {
            setMID_B(); //设置阀体材质
            setMID_S(); //设置阀杆材质
            setMID_I(); //设置阀瓣材质
            setMID_2(); //设置阀座材质
            setMID_9(); //设置填料    
        }); //加载所有材质
        loadSize(function () {
            setSize(); //设置尺寸    
        }); //加载所有口径
        loadPressure(function () {
            setPressure(); //设置压力等级
        }); //加载全部压力等级
        loadDesign(function () {
            setDesign(); //设置设计标准
        }); //加载全部设计标准
        loadConn(function () {
            setConn(); //设置连接方式
        }); //加载全部连接方式
        loadFran(function () {
            setFran(); //设置法兰标准
        })//加载全部法兰标准
        loadStruct(function () {
            setStruct(); //设置结构标准
        }); //加载结构标准
        loadSeal(function () {
            setSeal(); //设置密封等级
        })//加载密封等级
    }
    function checkLoading() {//检查加载
        var t = setTimeout(function () {
            if (loadPercent != 100) {
                checkLoading();
                $('#progressbar').progressbar({ value: loadPercent });
            }
            else {
                lblCkb();
                getCounts();
                $("#dialog").dialog("close");
                clearTimeout(t);
            }
        }, 500);
    }
    function checkSaving() {//检查保存
        var t = setTimeout(function () {
            if (savePercent != 100) {
                $('#progressbar').progressbar({ value: savePercent });
                checkSaving();
            }
            else {
                console.log('over');
                $("#dialog").dialog("close");
                clearTimeout(t);
                window.close();
            }
        }, 500)
    }
    function SaveAll() {
        SaveMID_B();
        SaveMID_S();
        SaveMID_I();
        SaveMID_2();
        SaveMID_9();
        SaveSize();
        SavePressure();
        SaveDesign();
        SaveConn();
        SaveFran();
        SaveStruct();
        SaveSeal();
    }
    //init
    $('#accordingContent').accordion({//初始化UI
        collapsible: true,
        heightStyle: 'content'
    });
    $("#dialog").dialog({//初始化Dialog
        autoOpen: false,
        width: 400,
        buttons: [
		{
		    text: "Cancel",
		    click: function () {
		        $(this).dialog("close");
		    }
		}
	]
    });
    loadAll();
    checkLoading();

    checkControl($('#ckbMID_B_All'), 'ckbMID_B_Sub');
    checkControl($('#ckbMID_S_All'), 'ckbMID_S_Sub');
    checkControl($('#ckbMID_I_All'), 'ckbMID_I_Sub');
    checkControl($('#ckbMID_2_All'), 'ckbMID_2_Sub');
    checkControl($('#ckbMID_9_All'), 'ckbMID_9_Sub');
    checkControl($('#ckbSize_All'), 'ckbSize_Sub');
    checkControl($('#ckbPressure_All'), 'ckbPressure_Sub');
    checkControl($('#ckbDesign_All'), 'ckbDesign_Sub');
    checkControl($('#ckbConn_All'), 'ckbConn_Sub');
    checkControl($('#ckbFran_All'), 'ckbFran_Sub');
    checkControl($('#ckbStruct_All'), 'ckbStruct_Sub');
    checkControl($('#ckbSeal_All'), 'ckbSeal_Sub');


    $('#button').button().click(function () {
        $("#dialog").dialog("open");
        $('#progressbar').progressbar({ value: 0 }); //初始化进度条
        SaveAll();
        checkSaving();
    })
})
